package com.loma.aidl_demo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class MyService extends Service {
    public MyService() {
    }

    private  String data = "默认数据";
    private  boolean running = false;

    @Override
    public IBinder onBind(Intent intent) {
     return    new IMyAidlInterface.Stub() {
            @Override
            public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

            }

         @Override
         public void setData(String data) throws RemoteException {
             MyService.this.data  = data;
         }
     };
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("zjt" , "onCreate");


        new Thread(){
            @Override
            public void run() {
                super.run();
                running = true;
                while (running){
                    System.out.println(data);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }.start();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("zjt" , "onDestroy");
        running = false;
    }
}